package com.youlai.boot.modules.brand.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.modules.brand.service.BrandMerchantService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "品牌商家关联接口")
@RestController
@RequestMapping("/api/v1/brand-merchant")
@RequiredArgsConstructor
public class BrandMerchantController {

    private final BrandMerchantService brandMerchantService;

    @Operation(summary = "获取品牌关联的商家列表")
    @GetMapping("/brands/{brandId}/merchants")
    public Result<List<Long>> getMerchantsByBrand(@PathVariable Long brandId) {
        return Result.success(brandMerchantService.getMerchantIdsByBrandId(brandId));
    }

    @Operation(summary = "获取商家关联的品牌列表")
    @GetMapping("/merchants/{merchantId}/brands")
    public Result<List<Long>> getBrandsByMerchant(@PathVariable Long merchantId) {
        return Result.success(brandMerchantService.getBrandIdsByMerchantId(merchantId));
    }

    @Operation(summary = "添加品牌商家关联")
    @PostMapping("/brands/{brandId}/merchants/{merchantId}")
    public Result<Boolean> addBrandMerchant(
            @PathVariable Long brandId,
            @PathVariable Long merchantId) {
        brandMerchantService.addBrandMerchant(brandId, merchantId);
        return Result.success(true);
    }

    @Operation(summary = "删除品牌商家关联")
    @DeleteMapping("/brands/{brandId}/merchants/{merchantId}")
    public Result<Boolean> removeBrandMerchant(
            @PathVariable Long brandId,
            @PathVariable Long merchantId) {
        brandMerchantService.removeBrandMerchant(brandId, merchantId);
        return Result.success(true);
    }
}